package com.bosssoft.goods.service.impl;

import cn.hutool.core.lang.Snowflake;
import com.bosssoft.goods.dao.GoodsManageDao;
import com.bosssoft.goods.domain.bean.GoodInfo;
import com.bosssoft.goods.domain.vo.*;
import com.bosssoft.goods.service.GoodsManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品管理服务实现类
 * @author Fang_Sir
 * @date 2021-04-20
 */
@Service
public class GoodsManageServiceImpl implements GoodsManageService {
    @Autowired
    private GoodsManageDao goodsManageDao;
    @Autowired
    private Snowflake snowflake;

    @Override
    public long addGood(AddGoodVO info) {
        GoodInfo good = new GoodInfo();
        good.setId(snowflake.nextId());
        good.setName(info.getName());
        good.setBrandId(info.getBrandId());
        good.setCatBrand(info.getBrandCat());
        good.setCatRoot(info.getCatArr()[0]);
        good.setCatFunc(info.getCatArr()[1]);
        good.setCatType(info.getCatArr()[2]);
        good.setStock(info.getStock());
        good.setPrice(info.getPrice());
        good.setContent(info.getContent());
        goodsManageDao.addGood(good);
        goodsManageDao.addGoodsImage(good.getId(), info.getPics());
        return good.getId();
    }

    @Override
    public boolean editGoodInfo(EditGoodInfoVO info) {
        return goodsManageDao.updateGoodInfo(info) > 0;
    }

    @Override
    public boolean deleteGood(long gid) {
        return goodsManageDao.deleteGood(gid) > 0;
    }
}
